package com.iwhalecloud.bss.kite.cucc.spec.impl.query;

import com.google.common.collect.Lists;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryProdRelService;
import com.iwhalecloud.bss.kite.dataservice.entity.ProdRelExt;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdRelInfo;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Product;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProdRelExtMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProdRelMapper;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ProdRelQueryService implements IQueryProdRelService {

	@Override
	public List<Product> listProdsByAProdIdAndRelType(String prodId, String relType) {
		ProdRelMapper prodRelMapper = SpringUtil.getBean(ProdRelMapper.class);
        List<Product> Product = prodRelMapper.selectProdByAProdIdAndRelType(prodId, relType);
        return Optional.ofNullable(Product).map((e) -> Lists.newArrayList(e)).orElse(Lists.newArrayList());
	}

	@Override
	public List<Product> listProdsByZProdIdAndRelType(String prodId, String relType) {
		ProdRelMapper prodRelMapper = SpringUtil.getBean(ProdRelMapper.class);
        List<Product> Product = prodRelMapper.selectProdByZProdIdAndRelType(prodId, relType);
        return Optional.ofNullable(Product).map((e) -> Lists.newArrayList(e)).orElse(Lists.newArrayList());
	}

	@Override
	public List<ProdRelInfo> listProdRelsByProdIdAndRelType(String prodId, String relType) {
		ProdRelMapper prodRelMapper = SpringUtil.getBean(ProdRelMapper.class);
        List<ProdRelInfo> ProdRel = prodRelMapper.selectProdRelByProdIdAndRelType(prodId, null);
        return Optional.ofNullable(ProdRel).map((e) -> Lists.newArrayList(e)).orElse(Lists.newArrayList());
	}

	@Override
	public List<Product> listFuncProdsByProdCatType(String prodId, String prodCatType, String lanId, String provId) {
		ProdRelMapper prodRelMapper = SpringUtil.getBean(ProdRelMapper.class);
        List<Product> productInfos = prodRelMapper.selectFuncProdsByProdCatType(prodId, prodCatType, lanId,
            provId);
        return productInfos;
	}

	@Override
	public List<Product> listFuncProdsByProdName(String prodId, String prodName, String lanId, String provId,
			String regionId, String staffId) {
		ProdRelMapper prodRelMapper = SpringUtil.getBean(ProdRelMapper.class);
        List<Product> productInfos = prodRelMapper.selectFuncProdsByProdName(prodId, prodName.toLowerCase(), lanId, provId, regionId, staffId);
        return productInfos;
	}

	@Override
	public ProdRelExt getProdRelExt(String prodRelId) {
		ProdRelExtMapper prodRelExtMapper = SpringUtil.getBean(ProdRelExtMapper.class);
        ProdRelExt prodRelExt = prodRelExtMapper.selectByPrimaryKey(prodRelId);
        return prodRelExt;
	}
}
